Ti.include('functions.js');
var win1 = Ti.UI.currentWindow;
var xhrXMLRecipes = Titanium.Network.createHTTPClient();
Ti.App.beerwatch = win1.beerwatch;
var data = [];


var win = Ti.UI.currentWindow;

var tableview = Ti.UI.createTableView({
	visible: true,
	editable: false,
	top: 0,
	height: WindowWidth
});


xhrXMLRecipes.onload = function() {
	if (this.status == 200) {
		var probes = -1;
		//Ti.API.info(this.responseText);
		var xml = Ti.XML.parseString(this.responseText);
		//This.API.info(xml);
		var xml_doc = xml.documentElement.getElementsByTagName("probe");
		for (var i=0;i<xml_doc.length;i++) {
			probe = xml_doc.item(i).getElementsByTagName("number").item(0).text;
			name = xml_doc.item(i).getElementsByTagName("name").item(0).text;
			var title = probe.toString() + " " + name;
			var row = Ti.UI.createTableViewRow({
        		title:title,
        		hasChild: true,
        		probe: probe.toString()
        	});
        	tableview.appendRow(row);
		}
	}
	
};


tableview.addEventListener('click',function(e) {
	var win1 = Titanium.UI.createWindow({  
    	title:'Beerwatch',
    	backgroundColor:'#fff',
    	url: 'showprobe.js',
    	probe: e.rowData.probe
	});
	Titanium.UI.currentTab.open(win1);
});

var probeUrl = "http://"+Ti.App.beerwatch+"/api.php?command=getProbes";
Ti.API.info(probeUrl);
xhrXMLRecipes.open("GET",probeUrl,false);
xhrXMLRecipes.send();


win1.add(tableview);

